﻿using System;
using System.Data.Entity;
using AceSoft.RetailPlus.Security;

namespace AceSoft.RetailPlus
{
    public class SysCompanyMock
    {
        public SysCompanyMock()
        {

            Security.Security _Security = new Security.Security();

            DbSet<SysCompany> _SysCompanies = _Security.SysCompanies;

            Console.WriteLine("Available companies");
            foreach (SysCompany _SysCompany in _SysCompanies)
            {
                Console.WriteLine(" ID: {2}   Company Code: {0}      Name: {1}", _SysCompany.Code, _SysCompany.Name, _SysCompany.ID);
            }

            Console.WriteLine("Deleting companies");
            foreach (SysCompany _SysCompany in _SysCompanies)
            {
                if (_SysCompany.ID == 0)
                {
                    Console.WriteLine(" Company Code: {0} is a default and cannot be deleted.", _SysCompany.Code);
                }
                else
                {
                    _SysCompanies.Remove(_SysCompany);
                    Console.WriteLine(" Company Code: {0} deleted.", _SysCompany.Code);
                }
            }

            Console.WriteLine("Adding companies");
            _SysCompanies.Add(new SysCompany { ID = 1, Code = "Code1", Name = "Company Name 1" });
            Console.WriteLine(" Company Code: {0} added.", "Code1");

            _SysCompanies.Add(new SysCompany { ID = 2, Code = "Code2", Name = "Company Name 2" });
            Console.WriteLine(" Company Code: {0} added.", "Code2");

            _Security.SaveChanges();

            Console.WriteLine("Relisting companies");
            foreach (SysCompany _SysCompany in _SysCompanies)
            {
                Console.WriteLine(" ID: {2}   Company Code: {0}      Name: {1}", _SysCompany.Code, _SysCompany.Name, _SysCompany.ID);
            }
        }
    }
}
